﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
    <script language="javascript" type="text/javascript">
        //排序按钮的点击事件
//        function sort(btnObj) {
        //            if (btnObj.className == "sort_desc")
        //                btnObj.className = "sort_asc";
        //            else
        //                btnObj.className = "sort_desc";
        //        }

        //启用
        function startFee() {
            var r = window.confirm("确定要启用此资费吗？资费启用后将不能修改和删除。");
            document.getElementById("operate_result_info").style.display = "block";
        }
        //删除
        function deleteFee() {
            var r = window.confirm("确定要删除此资费吗？");
            document.getElementById("operate_result_info").style.display = "block";
        }
    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="/index" class="index_on"></a></li>
        <li id="lia1"><a href="/role_list" class="role_off"></a></li>
        <li id="lia2"><a href="/admin_list" class="admin_off"></a></li>
        <li id="lia3"><a href="/fee_list" class="fee_off"></a></li>
        <li id="lia4"><a href="/account_list" class="account_off"></a></li>
        <li id="lia5"><a href="/service_list" class="service_off"></a></li>
        <li id="lia6"><a href="/bill_list" class="bill_off"></a></li>
        <li id="lia7"><a href="/report_list" class="report_off"></a></li>
        <li><a href="/userInfo" class="information_off"></a></li>
        <li><a href="/userModifyPwd" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--排序-->
        <div class="search_add">
            <div>
                <!--<input type="button" value="月租" class="sort_asc" onclick="sort(this);" />-->
                <input type="button" value="基费" class="sort_asc" onclick="jifei()"/>
                <input type="button" value="时长" class="sort_asc" onclick="shichang()"/>
            </div>
            <input type="button" value="增加" class="btn_add" onclick="location.href='fee_add.html';"/>
        </div>
        <!--启用操作的操作提示-->
        <div id="operate_result_info" class="operate_success">
            <img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>
            删除成功！
        </div>
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th>资费ID</th>
                    <th class="width100">资费名称</th>
                    <th>基本时长</th>
                    <th>基本费用</th>
                    <th>单位费用</th>
                    <th>创建时间</th>
                    <th>开通时间</th>
                    <th class="width50">状态</th>
                    <th class="width200"></th>
                </tr>
            </table>
            <p>业务说明：<br/>
                1、创建资费时，状态为暂停，记载创建时间；<br/>
                2、暂停状态下，可修改，可删除；<br/>
                3、开通后，记载开通时间，且开通后不能修改、不能再停用、也不能删除；<br/>
                4、业务账号修改资费时，在下月底统一触发，修改其关联的资费ID（此触发动作由程序处理）
            </p>
        </div>
        <!--分页-->
        <div id="pages">

        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)云科技有限公司</p>
</div>
</body>
<script src="/js/jquery-3.2.1.js"></script>
<script>
    show();
    costpage();
    function show() {

        $.ajax({
            url: "/selectAllModules",
            type: "post",
            success: function (result) {

                if (result.indexOf("角色管理") == -1) {
                    document.getElementById("lia1").style.display = "none"
                }
                if (result.indexOf("管理员") == -1) {
                    document.getElementById("lia2").style.display = "none"
                }
                if (result.indexOf("资费管理") == -1) {
                    document.getElementById("lia3").style.display = "none"
                }
                if (result.indexOf("账务账号") == -1) {
                    document.getElementById("lia4").style.display = "none"
                }
                if (result.indexOf("业务账号") == -1) {
                    document.getElementById("lia5").style.display = "none"
                }
                if (result.indexOf("账单管理") == -1) {
                    document.getElementById("lia6").style.display = "none"
                }
                if (result.indexOf("报表") == -1) {
                    document.getElementById("lia7").style.display = "none"
                }


            }

        });
    }
    function jifei() {
        $.ajax({
            url: "/selectAllCost1",
            type: "post",
            success: function (result) {
                $("#datalist  tr:not(:first)").empty("");
                 data(result);
            }
        });

    }
    function shichang() {
        $.ajax({
            url: "/selectAllCost2",
            type: "post",
            success: function (result) {
                $("#datalist  tr:not(:first)").empty("");
                data(result);
            }
        });

    }
    function data(result) {
        for (var i = 0; i < result.length; i++) {
            var costBean = result[i];
            console.log(costBean);
            var tr = $("<tr></tr>");
            var tdid = $("<td></td>").text(costBean.costId);
            var costname = $("<td></td>");
            var a = $("<a href='/fee_detail?costId="+costBean.costId+"'></a>").text(costBean.name);
            costname.append(a);
            var baseDuration = $("<td></td>").text(costBean.baseDuration);
            var baseCost = $("<td></td>").text(costBean.baseCost);
            var unitCost = $("<td></td>").text(costBean.unitCost);
            var creatime = $("<td></td>").text(costBean.creatime);
            var startime = $("<td></td>").text(costBean.startime);
            var status = $("<td></td>").text(costBean.status == '0' ? '暂停' : '启用');
            if (costBean.status==0) {
                var changeBtn = $("<td></td>").css("display", "block");
            }else {
                changeBtn = $("<td></td>").css("display", "none");
            }
            var a1 = $("<input type='button' value='暂停' class='btn_pause' id='btn' onclick='setState(" + costBean.costId + "," + costBean.status + ")'/>").val(costBean.status == 1 ? '暂停' : '启用');
            var a2 = $("<input type='button' value='修改' class='btn_modify'  onclick='tiao(" + costBean.costId + ")'/>");
            var a3 = $("<input type='button' value='删除' class='btn_delete'  onclick='setDelState(" + costBean.costId + "," + costBean.status + ")'/>");

            changeBtn.append(a1).append(a2).append(a3);
            tr.append(tdid).append(costname).append(baseDuration).append(baseCost)
                    .append(unitCost).append(creatime).append(startime).append(status).append(changeBtn);
            $("#datalist").append(tr);

        }
    }

    function costpage() {
        $.ajax({
            url: "/costpage",
            type: "post",
            data: {
                pageNum: 1,
                pageSize: 3
            },
            success: function (result) {
                resultData(result);
            }
        });
    }
    function page(pagenum) {
        $.ajax({
            url: "/costpage",
            type: "post",
            data: {
                pageNum: pagenum,
                pageSize: 3
            },
            success: function (result) {
                resultData(result);
            }
        });
    }
    function tiao(id) {
        window.location.href = "/fee_modi?id=" + id;
    }

    function setState(feeId, status) {
        $.ajax({
            url: "/startOrStop",
            type: "post",
            data: {
                costId: feeId,
                status: status
            },
            success: function (result) {
                window.location.href = result.msg
            }

        });

    }
    function setDelState(feeId,status) {
        $.ajax({
            url: "/delCost",
            type: "post",
            data: {
                costId: feeId,
                status: status
            },
            success: function (result) {
                window.location.href = result.msg
            }

        });

    }

    function resultData(result) {
        $("#datalist").html("");
        $("#datalist").append("<tr>" +
                "<th>资费ID</th>" +
                "<th class='width100'>资费名称</th>" +
                "<th >基本时长</th>" +
                "<th >基本费用</th>" +
                "<th >单位费用</th>" +
                "<th >创建时间</th>" +
                "<th >开通时间</th>" +
                "<th class='width50'>状态</th>" +
                "<th class='width200'></th>" +
                "</tr>");
        var pagenum = result.pageNum;
        //每页显示几条数据
        var pagesize = result.pageSize;
        var size = result.size;
        var startrow = result.startRow;
        var endrow = result.startRow;
        var total = result.total;
        var pages = result.pages;
        var firstpage = result.firstPage;
        var prepage = result.prePage;
        var nextpage = result.nextPage;
        var lastpage = result.lastPage;
        var isfirstpage = result.isFirstPage;
        var islastpage = result.isLastPage;
        var haspreviouspage = result.hasPreviiousPage;
        var hasnextpage = result.hasNextPage;
        var navigatepages = result.navigatePages;
        var navigatepagenums = result.navigatepageNums;
        var costList = result.list;

        if (isfirstpage) {
            prepage = firstpage
        }
        if (islastpage) {
            nextpage = lastpage;
        }
        for (var i = 0; i < costList.length; i++) {
            var costBean = costList[i];
            console.log(costBean);
            var tr = $("<tr></tr>");
            var tdid = $("<td></td>").text(costBean.costId);
            var costname = $("<td></td>");
            var a = $("<a href='/fee_detail?costId="+costBean.costId+"'></a>").text(costBean.name);
            costname.append(a);
            var baseDuration = $("<td></td>").text(costBean.baseDuration);
            var baseCost = $("<td></td>").text(costBean.baseCost);
            var unitCost = $("<td></td>").text(costBean.unitCost);
            var creatime = $("<td></td>").text(costBean.creatime);
            var startime = $("<td></td>").text(costBean.startime);
            var status = $("<td></td>").text(costBean.status == '0' ? '暂停' : '启用');
            if (costBean.status==0) {
                var changeBtn = $("<td></td>").css("display", "block");
            }else {
                changeBtn = $("<td></td>").css("display", "none");
            }
            var a1 = $("<input type='button' value='暂停' class='btn_pause' id='btn' onclick='setState(" + costBean.costId + "," + costBean.status + ")'/>").val(costBean.status == 1 ? '暂停' : '启用');
            var a2 = $("<input type='button' value='修改' class='btn_modify'  onclick='tiao(" + costBean.costId + ")'/>");
            var a3 = $("<input type='button' value='删除' class='btn_delete'  onclick='setDelState(" + costBean.costId + "," + costBean.status + ")'/>");

            changeBtn.append(a1).append(a2).append(a3);
            tr.append(tdid).append(costname).append(baseDuration).append(baseCost)
                    .append(unitCost).append(creatime).append(startime).append(status).append(changeBtn);
            $("#datalist").append(tr);

        }

        $("#pages").html("");
        var a11 = $("<a href='javascript:void(0)' onclick='page(" + firstpage + ")'></a>").text("首页");
        var a12 = $("<a href='javascript:void(0)' onclick='page(" + prepage + ")'></a>").text("上一页");
        $("#pages").append(a11).append(a12);
        for (var k = 1; k <= lastpage; k++) {
            $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + k + ")' >" + k + "</a>"));
        }
        var a13 = $("<a href='javascript:void(0)' onclick='page(" + nextpage + ")'></a>").text("下一页");
        var a14 = $("<a href='javascript:void(0)' onclick='page(" + lastpage + ")'></a>").text("尾页");
        $("#pages").append(a13).append(a14);
    }


</script>
</html>
